package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.BusinessLine;
import com.ruoyi.system.service.IBusinessLineService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务线Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/system/businessline")
public class BusinessLineController extends BaseController {
    @Autowired
    private IBusinessLineService businessLineService;


    @PreAuthorize("@ss.hasPermi('system:businessline:list')")
    @GetMapping("/getAll")
    public AjaxResult getAll() {
        List<BusinessLine> list = businessLineService.list();
        return AjaxResult.success(list);
    }


    /**
     * 查询业务线列表
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessLine businessLine) {
        startPage();
        List<BusinessLine> list = businessLineService.selectBusinessLineList(businessLine);


        return getDataTable(list);
    }

    /**
     * 导出业务线列表
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:export')")
    @Log(title = "业务线", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessLine businessLine) {
        List<BusinessLine> list = businessLineService.selectBusinessLineList(businessLine);
        ExcelUtil<BusinessLine> util = new ExcelUtil<BusinessLine>(BusinessLine.class);
        util.exportExcel(response, list, "业务线数据");
    }

    /**
     * 获取业务线详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(businessLineService.selectBusinessLineById(id));
    }

    /**
     * 新增业务线
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:add')")
    @Log(title = "业务线", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessLine businessLine) {
        return toAjax(businessLineService.insertBusinessLine(businessLine));
    }

    /**
     * 修改业务线
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:edit')")
    @Log(title = "业务线", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessLine businessLine) {
        return toAjax(businessLineService.updateBusinessLine(businessLine));
    }

    /**
     * 删除业务线
     */
    @PreAuthorize("@ss.hasPermi('system:businessline:remove')")
    @Log(title = "业务线", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(businessLineService.deleteBusinessLineByIds(ids));
    }
}
